//
//  ILGMRCViewController.m
//  ILGDemo
//
//  Created by happy on 2020/2/18.
//  Copyright © 2020 Happy. All rights reserved.
//

#import "ILGMRCViewController.h"

#import "ILGTestModel.h"
#import "ILGView.h"

@interface ILGMRCViewController ()
@property (nonatomic, copy) ILGTestModelBlock testModelBlock;
@property (nonatomic, strong) ILGTestModel *testModel;
@end

@implementation ILGMRCViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self createUI];
    
    [self testForOthers];
}

- (void)dealloc {
    [_testModel release];
//    [_testModelBlock release];

    [super dealloc];
    
    NSLog(@"%s", __func__);
}

#pragma mark - UI

- (void)createUI {
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setTitle:@"点一下" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.view);
        make.size.mas_equalTo(CGSizeMake(90, 30));
    }];
}

#pragma mark - event

- (void)buttonClicked:(UIButton *)button {
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        if (self.testModelBlock) {
            self.testModelBlock(@"ZhangSan");
        }
    });
}

#pragma mark - other


- (void)testForOthers {
//    ILGView  *view = [[ILGView alloc] init];
//    [view release];
//    UIView  *view2 = [[UIView alloc] init];
//    [view release];
    
//    @autoreleasepool {
//         for (int i = 0; i < 10; i++) {
//             ILGView  *view = [[[ILGView alloc] initWithFrame:CGRectMake(0, 0, 1000, 1000)] autorelease];
//
//             NSLog(@"for loop：current loop ended");
//         }
//    }

        
    NSLog(@"for loop：ended");
    
//    ILGTestModel *testModel = [[ILGTestModel alloc] init];
//    self.testModel = testModel;
//    [testModel release];
//
//    __block __strong ILGTestModel *blockModel = self.testModel;
//    _testModelBlock = ^{
//        NSLog(@"testModelBlock called, age = %@", testModel);
//    };
//    NSLog(@"%@", [_testModelBlock class]);
}

@end
